package com.ostrich.module_more.themes

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.ostrich.library_base.BaseMvvmFragment
import com.ostrich.library_common.utils.LoggerUtils
import com.ostrich.module_more.R
import com.ostrich.module_more.databinding.MoreFragmentThemesBinding
import com.ostrich.module_more.themes.adapter.ThemesFragmentAdapter
import com.ostrich.module_more.themes.entity.ThemesTabEntity
import io.reactivex.Observer
import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers


class ThemesFragment : BaseMvvmFragment<MoreFragmentThemesBinding,ThemesViewModel>() {
    private lateinit var themesFragmentAdapter: ThemesFragmentAdapter
    override fun initView() {


    }

    override fun initData() {
        viewModel.tabList().subscribeOn(Schedulers.io())//子线程耗时操作
            .observeOn(AndroidSchedulers.mainThread())//主线程更新UI
            .subscribe(object :Observer<ThemesTabEntity>{
                override fun onNext(t: ThemesTabEntity) {
                   LoggerUtils.d(TAG,t.toString())

                    binding?.let {
                        themesFragmentAdapter = ThemesFragmentAdapter(t.tabInfo.tabList.toMutableList(),childFragmentManager)
                        it.vpContent.adapter = themesFragmentAdapter
                        it.tabLayout.setupWithViewPager(it.vpContent)

                    }



                }

                override fun onError(e: Throwable) {

                }

                override fun onSubscribe(d: Disposable) {

                }

                override fun onComplete() {
                }

            })


    }

    override fun initListener() {

    }

    override fun bindLayout(): Int {
        return R.layout.more_fragment_themes
    }

    override fun getJVMClass(): Class<ThemesViewModel> {
       return ThemesViewModel::class.java
    }

    companion object{
        const val TAG = "ThemesFragment"
    }

}